package com.heima.search.listener;

import com.alibaba.fastjson.JSON;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.messafe.vos.SearchArticleVo;
import com.heima.search.service.UserSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class SyncArticleListener {

    @Autowired
    private UserSearchService userSearchService;

    @KafkaListener(topics = ArticleConstants.ARTICLE_ES_SYNC_TOPIC)
    public void syncArticleToEs(String message){
        //1.转化类型
        SearchArticleVo searchArticleVo = JSON.parseObject(message, SearchArticleVo.class);
        //2.写入数据到es中
        userSearchService.writerArticleToEs(searchArticleVo);
    }
}
